using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The DistrictCodeTableManager class is responsible for managing BO.DistrictCodeTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class DistrictCodeTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all DistrictCodeTable objects in the database.
        /// </summary>
        /// <returns>A list with all DistrictCodeTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static DistrictCodeTableList GetList(Int16 countryCode)
        {
            return DistrictCodeTableDB.GetList(countryCode);
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static DistrictCodeTableList GetList()
        {
            return DistrictCodeTableDB.GetList();
        }

        /// <summary>
        /// Gets a single DistrictCodeTable from the database without its data.
        /// </summary>
        /// <param name="districtCode">The DistrictCode of the DistrictCodeTable in the database.</param>
        /// <returns>A DistrictCodeTable object when the DistrictCode exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DistrictCodeTable GetItem(short districtCode)
        {
            return GetItem(districtCode, false);
        }

        /// <summary>
        /// Gets a single DistrictCodeTable from the database.
        /// </summary>
        /// <param name="districtCode">The DistrictCode of the DistrictCodeTable in the database.</param>
        /// <param name="getDistrictCodeTableRecords">Determines whether to load all associated DistrictCodeTable records as well.</param>
        /// <returns>
        /// A DistrictCodeTable object when the DistrictCode exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DistrictCodeTable GetItem(short districtCode, bool getDistrictCodeTableRecords)
        {
            DistrictCodeTable myDistrictCodeTable = DistrictCodeTableDB.GetItem(districtCode);
            return myDistrictCodeTable;
        }

        /// <summary>
        /// Saves a DistrictCodeTable in the database.
        /// </summary>
        /// <param name="myDistrictCodeTable">The DistrictCodeTable instance to save.</param>
        /// <returns>The new DistrictCode if the DistrictCodeTable is new in the database or the existing DistrictCode when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static short Save(DistrictCodeTable myDistrictCodeTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                short districtCodeTableDistrictCode = DistrictCodeTableDB.Save(myDistrictCodeTable);

                //  Assign the DistrictCodeTable its new (or existing DistrictCode).
                myDistrictCodeTable.DistrictCode = districtCodeTableDistrictCode;

                myTransactionScope.Complete();

                return districtCodeTableDistrictCode;
            }
        }

        /// <summary>
        /// Deletes a DistrictCodeTable from the database.
        /// </summary>
        /// <param name="myDistrictCodeTable">The DistrictCodeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(DistrictCodeTable myDistrictCodeTable)
        {
            return DistrictCodeTableDB.Delete(myDistrictCodeTable.DistrictCode);
        }

        #endregion

    }

}
